<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<?php
function head($title){
echo'<title>'.$title.' - malendziak cms installer</title>';
?></head>
<body><?php
themeBanner('images/banner.png');
}
function fileList($src){
$dir=opendir($src);
while(false!==($file=readdir($dir)))if($file!='.'&&$file!='..')$answer[]=$file;
return $answer;
}
include_once'themes/default/index.php';
if(!isset($_POST['step'])){
head('Select language');
echo'<form action=install.php method=post>';
themeFormBegin();
$languages=fileList('language');
$input='<div id=SELECT><select name="language">';
for($i=0;$i<count($languages);$i++)$input.='<option value="'.$languages[$i].'">'.$languages[$i].'</option>';
$input.='</select></div>';
themeFormInput('Select language',$input);
echo'<input type=hidden name=step value=1>';
themeFormInput('','<input type=submit value=OK>');
themeFormEnd();
echo'</form>';
}
else{
include_once'language/'.$_POST['language'];
if($_POST['step']==1){
head($language['cms'][50]);
themeTitle($language['cms'][50]);
echo'<form action="install.php" method=post>';
themeFormBegin();
themeFormInput($language['cms'][48],'<input type=text name=url value="'.$_POST['url'].'">');
themeFormInput($language['cms'][0],'<input type=text name=login value="'.$_POST['login'].'">');
themeFormInput($language['cms'][1],'<input type=password name=password>');
themeFormInput($language['cms'][51],'<input type=text name=name value="'.$_POST['name'].'">');
themeFormInput($language['cms'][53],'<input type=text name=prefix value="'.$_POST['prefix'].'">');
themeFormInput('','<input type=submit value=OK>');
echo'<input type=hidden name=language value="'.$_POST['language'].'"><input type=hidden name=step value=2>';
themeFormEnd();
echo'</form>';
}
else if($_POST['step']==2){
mysql_connect($_POST['url'],$_POST['login'],$_POST['password']);
@mysql_select_db($_POST['name']) or $error=1;
if(isset($error)){
head($language['cms'][50]);
themeTitle($language['cms'][50]);
echo $language['cms'][52].'<form action=install.php method=post><input type=hidden name=url value="'.$_POST['url'].'"><input type=hidden name=login value="'.$_POST['login'].'"><input type=hidden name=name value="'.$_POST['name'].'"><input type=hidden name=prefix value="'.$_POST['prefix'].'"><input type=hidden name=language value="'.$_POST['language'].'"><input type=hidden name=step value=1><input type=submit value="'.$language['cms'][39].'"></form>';
}
else{
head($language['cms'][54]);
themeTitle($language['cms'][54]);
echo'<form action=install.php method=post><input type=hidden name=url value="'.$_POST['url'].'"><input type=hidden name=mysqllogin value="'.$_POST['login'].'"><input type=hidden name=mysqlpassword value="'.$_POST['password'].'"><input type=hidden name=name value="'.$_POST['name'].'"><input type=hidden name=prefix value="'.$_POST['prefix'].'"><input type=hidden name=language value="'.$_POST['language'].'"><input type=hidden name=step value=3>';
themeFormBegin();
themeFormInput($language['cms'][0],'<input type=text name=login>');
themeFormInput($language['cms'][1],'<input type=password name=password>');
themeFormInput($language['cms'][13],'<input type=text name=email>');
themeFormInput('','<input type=submit value=OK>');
themeFormEnd();
echo'</form>';
}
}
else if($_POST['step']==3){
head($language['cms'][55]);
themeTitle($language['cms'][55]);
echo $language['cms'][56].' : config.php<br>';
$file=fopen('config.php','w');
fputs($file,'<?php
$mysql_server=\''.$_POST['url'].'\';
$mysql_login=\''.$_POST['mysqllogin'].'\';
$mysql_password=\''.$_POST['mysqlpassword'].'\';
$mysql_database_name=\''.$_POST['name'].'\';
$mysql_prefix=\''.$_POST['prefix'].'\';
?>');
fclose($file);
echo'OK<br>';
echo $language['cms'][56].' : index.php<br>';
$file=fopen('index.php','w');
fputs($file,'<?php
include_once\'config.php\';
mysql_connect($mysql_server,$mysql_login,$mysql_password);
mysql_set_charset(\'UTF8\');
mysql_select_db($mysql_database_name);
$page=mysql_query(\'SELECT `start_page` FROM `\'.$mysql_prefix.\'settings`\');
header(\'Location:\'.mysql_result($page,0,\'start_page\'));
?>');
fclose($file);
echo'OK<br>';
echo $language['cms'][56].' : mysql database<br>';
mysql_connect($_POST['url'],$_POST['mysqllogin'],$_POST['mysqlpassword']);
mysql_set_charset('UTF8');
mysql_select_db($_POST['name']);
mysql_query('CREATE TABLE IF NOT EXISTS `'.$_POST['prefix'].'admin_panel_buttons` (
  `id` text COLLATE utf8_unicode_ci NOT NULL,
  `img` text COLLATE utf8_unicode_ci NOT NULL,
  `module` text COLLATE utf8_unicode_ci NOT NULL,
  `language` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci');
mysql_query('INSERT INTO `'.$_POST['prefix'].'admin_panel_buttons` (`id`, `img`, `module`, `language`) VALUES
(\'cms_edit_page\', \'images/admin_panel_button/cms_edit_page.png\', \'cms\', 25),
(\'cms_edit_users\', \'images/admin_panel_button/cms_edit_users.png\', \'cms\', 24),
(\'cms_main_settings\', \'images/admin_panel_button/cms_main_settings.png\', \'cms\', 26),
(\'cms_nawigation_edit\', \'images/admin_panel_button/cms_nawigation_edit.png\', \'cms\', 46)');
mysql_query('CREATE TABLE IF NOT EXISTS `'.$_POST['prefix'].'admin_privileges_list` (
  `name` text COLLATE utf8_unicode_ci NOT NULL,
  `module` text COLLATE utf8_unicode_ci NOT NULL,
  `language` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci');
mysql_query('INSERT INTO `'.$_POST['prefix'].'admin_privileges_list` (`name`, `module`, `language`) VALUES
(\'cms_edit_users\', \'cms\', 24),
(\'cms_edit_page\', \'cms\', 25),
(\'cms_main_settings\', \'cms\', 26),
(\'cms_edit_admins\', \'cms\', 45),
(\'cms_nawigation_edit\', \'cms\', 46)');
mysql_query('CREATE TABLE IF NOT EXISTS `'.$_POST['prefix'].'nawigation` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `url` text COLLATE utf8_unicode_ci NOT NULL,
  `title` text COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=7');
mysql_query('INSERT INTO `'.$_POST['prefix'].'nawigation` (`id`, `url`, `title`) VALUES
(1, \'page.php?id=1\', \'main page\')');
mysql_query('CREATE TABLE IF NOT EXISTS `'.$_POST['prefix'].'pages` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` text COLLATE utf8_unicode_ci NOT NULL,
  `text` text COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=5 ;');
mysql_query('INSERT INTO `'.$_POST['prefix'].'pages` (`id`, `title`, `text`) VALUES
(1, \'main page\', \'main pages value\')');
mysql_query('CREATE TABLE IF NOT EXISTS `'.$_POST['prefix'].'settings` (
  `title` text COLLATE utf8_unicode_ci NOT NULL,
  `banner` text COLLATE utf8_unicode_ci NOT NULL,
  `foot` text COLLATE utf8_unicode_ci NOT NULL,
  `start_page` text COLLATE utf8_unicode_ci NOT NULL,
  `theme` text COLLATE utf8_unicode_ci NOT NULL,
  `language` text COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci');
mysql_query('INSERT INTO `'.$_POST['prefix'].'settings` (`title`, `banner`, `foot`, `start_page`, `theme`, `language`) VALUES
(\'malendziak cms\', \'images/banner.png\', \'foot text\', \'page.php?id=1\', \'default\', \''.$_POST['language'].'\')');
mysql_query('CREATE TABLE IF NOT EXISTS `'.$_POST['prefix'].'users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `login` text COLLATE utf8_unicode_ci NOT NULL,
  `password` text COLLATE utf8_unicode_ci NOT NULL,
  `email` text COLLATE utf8_unicode_ci NOT NULL,
  `admin` int(11) NOT NULL DEFAULT \'0\',
  `admin_privileges` text COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=14');
mysql_query('INSERT INTO `'.$_POST['prefix'].'users` (`id`, `login`, `password`, `email`, `admin`, `admin_privileges`) VALUES
(1, \''.$_POST['login'].'\', \''.md5($_POST['password']).'\', \''.$_POST['email'].'\', 2, \'cms_edit_page cms_edit_users cms_main_settings cms_edit_admins cms_nawigation_edit\')');
echo'OK<br>';
echo $language['cms'][57].'<br><a href=index.php>'.$language['cms'][58].'</a>';
}
}
themeFoot('malendziak cms','installer');
?>
</body>
</html>